// API 响应通用接口
export interface ApiResponse<T = any> {
  code: number;
  message: string;
  data: T;
  success: boolean;
  timestamp?: number;
}

// 分页响应接口
export interface PaginatedResponse<T = any> {
  list: T[];
  total: number;
  current: number;
  pageSize: number;
  pages: number;
}

// 分页请求参数
export interface PaginationParams {
  current?: number;
  pageSize?: number;
  [key: string]: any;
}

// 请求配置扩展
export interface RequestConfig {
  showLoading?: boolean;
  showError?: boolean;
  showSuccess?: boolean;
  timeout?: number;
}

// 管理员登录请求类型
export interface AdminLoginDto {
  username: string;
  password: string;
  captchaId: string;
  captchaCode: string;
}

// 错误响应接口
export interface ApiError {
  code: number;
  message: string;
  details?: any;
  timestamp: number;
}

// 用户认证相关类型
export interface LoginParams {
  username: string;
  password: string;
  remember?: boolean;
}

export interface UserInfo {
  id: number;
  username: string;
  email: string;
  avatar?: string;
  roles: string[];
  permissions: string[];
  lastLoginTime?: string;
}

export interface AuthTokens {
  accessToken: string;
  refreshToken: string;
  expiresIn: number;
}

// ===== 新增接口相关类型定义 =====

// 分页响应类型（与后端保持一致）
export interface PageResp {
  数据列表: any[];
  总记录数: number;
}

// 切换租户相关类型
export interface SwitchTenantDto {
  tenantId: string;
}

export interface SwitchTenantResponseDto {
  token: string;
  tenant: {
    id: string;
    name: string;
    status: string;
  };
}

// 租户管理相关类型
export interface TenantQueryDto {
  page?: number;
  limit?: number;
  name?: string;
  status?: string;
}

export interface CreateTenantDto {
  name: string;
  code: string;
  description?: string;
}

export interface UpdateTenantDto {
  id: string;
  name?: string;
  description?: string;
}

export interface UpdateTenantStatusDto {
  id: string;
  status: string;
}

export interface TenantResponseDto {
  id: string;
  name: string;
  code: string;
  status: string;
  description?: string;
  createTime?: string;
  updateTime?: string;
}

// 用户管理相关类型
export interface UserResponseDto {
  id: string;
  username: string;
  name: string;
  email?: string;
  phone?: string;
  avatar?: string;
  status: string;
  createTime?: string;
  updateTime?: string;
  lastLoginTime?: string;
  tenantInfo?: TenantInfo[];
  isActive?: boolean;
}

export interface UpdateUserStatusDto {
  id: string;
  status: string;
}

// 用户查询参数扩展
export interface UserQueryParams {
  page?: number;
  limit?: number;
  status?: string;
  name?: string;
  email?: string;
  phone?: string;
  createTimeStart?: string;
  createTimeEnd?: string;
  tenantId?: string;
  username?: string;
}

// 用户状态枚举
export enum UserStatus {
  ACTIVE = 'active',
  INACTIVE = 'inactive',
  BANNED = 'banned',
  PENDING = 'pending'
}

// 用户表格行数据类型
export interface UserTableRow extends UserResponseDto {
  key?: string;
}

// 用户搜索表单类型
export interface UserSearchForm {
  name?: string;
  status?: UserStatus | string;
  dateRange?: [string, string];
  tenantId?: string;
  email?: string;
  phone?: string;
  createTimeStart?: string;
  createTimeEnd?: string;
}

// 租户信息类型
export interface TenantInfo {
  id: string;
  name: string;
  status: string;
  joinTime?: string;
}

// 批量操作类型
export interface BatchUserOperationDto {
  userIds: string[];
  operation: 'activate' | 'deactivate' | 'ban' | 'delete';
  reason?: string;
}

// 管理员管理相关类型
export interface CreateAdminDto {
  username: string;
  password: string;
  name: string;
  email?: string;
  phone?: string;
  adminType: string;
}

export interface AdminResponseDto {
  id: string;
  username: string;
  name: string;
  email?: string;
  phone?: string;
  avatar?: string;
  adminType: string;
  status: string;
  createTime?: string;
  updateTime?: string;
}

export interface GetUserDetailDto {
  id: string;
}

export interface UpdateAdminRequestDto {
  id: string;
  name?: string;
  email?: string;
  phone?: string;
  status?: string;
}

export interface DeleteAdminRequestDto {
  id: string;
}

// 接单员申请相关类型
export interface TakerApplicationDto {
  id: string;
  userId: string;
  tenantId: string;
  reason?: string;
  contactInfo?: string;
  status: 'pending' | 'approved' | 'rejected';
  approvedBy?: string;
  approvedTime?: string;
  rejectReason?: string;
  createTime: string;
}

export interface ApproveTakerApplicationDto {
  id: string;
  approved: boolean;
  rejectReason?: string;
}

export interface GetTakerApplicationDto {
  id: string;
}

// 文件管理相关类型
export interface FileUploadDto {
  file: File;
  category?: string;
}

export interface FileDeleteDto {
  fileId: string;
}

export interface PresignedUploadUrlDto {
  fileName: string;
  fileType: string;
  category?: string;
}

export interface ResponseDto {
  success: boolean;
  message: string;
  data?: any;
}

// 用户端相关类型
export interface WechatLoginDto {
  code: string;
  userInfo?: any;
}

export interface WechatLoginResponseDto {
  token: string;
  user: {
    id: string;
    openId: string;
    nickName?: string;
    avatar?: string;
  };
}

export interface UserSchoolListResponseDto {
  schools: {
    id: string;
    name: string;
    status: string;
  }[];
}

export interface SwitchSchoolDto {
  schoolId: string;
}

export interface SwitchSchoolResponseDto {
  success: boolean;
  currentSchool: {
    id: string;
    name: string;
  };
}

export interface CurrentSchoolInfoDto {
  id: string;
  name: string;
  status: string;
  address?: string;
}

export interface ApplyTakerRequestDto {
  tenantId: string;
  reason?: string;
  contactInfo?: string;
}

export interface ApplyTakerResponseDto {
  success: boolean;
  message: string;
  applicationId: string;
}
